<template>
	<view class="wrap">
		<view class="topBc"></view>
		<view class="content formWrap">
			<view class="title" style="margin-top: 0;">债权、债务情况</view>
			<u-form :model="formData" ref="uForm" :rules="rules">
				<u-form-item v-if="formKeys.forloanfloatation" label="本年外方股东贷款借款" prop="forloanfloatation" required label-width="auto" borderBottom>
					<u-input v-model="formData.forloanfloatation" placeholder="请输入" border="none" inputAlign="right">
						<view
							slot="prefix" style="transform: translateX(-12rpx);"
							@click="$util.showModal({content: `报告年度内，投资总额内外国投资者以自有资金向外商投资企业 (机构) 提供的期限1年以上的中长期贷款本金
							和针对外国股东贷款所获得的利息，包括债券和信贷`})"
						>
							<u-icon name="question-circle" :color="bgColor" size="34rpx"></u-icon>
						</view>
						<u--text
							text="万(美元)"
							slot="suffix"
						></u--text>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.forloanrepayment" label="本年外方股东贷款还款" prop="forloanrepayment" required label-width="auto" borderBottom>
					<u-input v-model="formData.forloanrepayment" placeholder="请输入" border="none" inputAlign="right">
						<view
							slot="prefix" style="transform: translateX(-12rpx);"
							@click="$util.showModal({content: `报告年度内，外商投资企业 (机构) 对外国投资者偿还的期限1年以上的中长期贷款本金和利息，包括债券和信贷。`})"
						>
							<u-icon name="question-circle" :color="bgColor" size="34rpx"></u-icon>
						</view>
						<u--text
							text="万(美元)"
							slot="suffix"
						></u--text>
					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.liabilitiestotal" label="对境外投资者的债务合计" prop="liabilitiestotal" required label-width="auto" borderBottom>
					<u-input v-model="formData.liabilitiestotal" placeholder="请输入" border="none" inputAlign="right">
						<view
							slot="prefix" style="transform: translateX(-12rpx);"
							@click="$util.showModal({content: `截至报告年度年末，外商投资企业(机构) 对境外投资者承担的债务，包括应付债券、短期借款、应付票据、
							应付账款、预收款项、应付利息、应付胀利，其他应付款、长期借款、长期应付款和其他债务`})"
						>
							<u-icon name="question-circle" :color="bgColor" size="34rpx"></u-icon>
						</view>
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.depositam" label="在境外投资者的存款合计" prop="depositam" required label-width="auto" borderBottom>
					<u-input v-model="formData.depositam" placeholder="请输入" border="none" inputAlign="right">
						<view
							slot="prefix" style="transform: translateX(-12rpx);"
							@click="$util.showModal({content: `当境外投资者为存款类金融机构时，截至报告年度年末，
							企业(机构)在保留所有权的条件下存储在境外投资者处的资金。`})"
						>
							<u-icon name="question-circle" :color="bgColor" size="34rpx"></u-icon>
						</view>
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>					</u-input>
				</u-form-item>
				<u-form-item v-if="formKeys.credrighttotal" label="对境外投资者的债权合计" prop="credrighttotal" required label-width="auto" borderBottom>
					<u-input v-model="formData.credrighttotal" placeholder="请输入" border="none" inputAlign="right">
						<view
							slot="prefix" style="transform: translateX(-12rpx);"
							@click="$util.showModal({content: `截至报告年度年末，外商投资企业(机构)对境外投资者享有的债权，包括债券投资、应收票据、应收账款、
							预付款项、应收利息、应收股利、其他应收款、长期应收款和其他债券。不是计提减值准备后的净值。`})"
						>
							<u-icon name="question-circle" :color="bgColor" size="34rpx"></u-icon>
						</view>
						<view class="units_suffix" slot="suffix">
							<text><text class="units_suffix_colorRed">万</text>(元)</text>
						</view>					</u-input>
				</u-form-item>
			</u-form>
			
		</view>
		<view class="submitBtn_bc"></view>
		<view class="submitBtn_ubtn">
			<u-button :disabled="!$util.submitState(year,state)" @click="submit()">提交</u-button>
		</view>
	</view>
</template>

<script>
export default {
	data(){
		return{
			minFormName: 'debtinfo', //小表单类型名
			regnoInfo: this.$store.state.regnoInfo,
			year: '',
			state: '',
			bgColor: this.$config.bgColor,
			
			formData: {
				forloanfloatation: '',
				forloanrepayment: '',
				liabilitiestotal: '',
				depositam: '',
				credrighttotal: '',
			},
			rules: {},
			rulesAll: {
				forloanfloatation: this.$typeData.ruleData.moneyRule,
				forloanrepayment: this.$typeData.ruleData.moneyRule,
				liabilitiestotal: this.$typeData.ruleData.moneyRule,
				depositam: this.$typeData.ruleData.moneyRule,
				credrighttotal: this.$typeData.ruleData.moneyRule,
			},
			formKeys: {},
		}
	},
	onLoad(option) {
		this.year = option.year;
		this.state = option.state;
		this.getFormKey();
		this.getFormData();
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules)
	},
	methods:{
		// 获取小表单数据
		getFormData(){
			let url = this.$typeData.minFormUrl.get(this.minFormName);
			if(!url){
				uni.showModal({
					title: '暂无接口'
				})
				return;
			}
			this.$http.sendRequest({
				url: url,
				data: {
					regno: this.regnoInfo.regno,
					ancheyear: this.year
				}
			})
			.then(res=>{
				console.log('接口返回',res.data);
				let data = res.data;				let keys = Object.keys(this.formKeys);				keys.forEach(item=>{					this.formData[item] = data[item];				})
				console.log(789789,this.formData);
			})
			.catch(err=>{})
		},
		//获取小表单拥有字段
		getFormKey(){
			let formKeys = this.$util.getFormKeys(this.minFormName,this.regnoInfo.enttype);
			this.formKeys = formKeys;
			let keys = Object.keys(formKeys);
			keys.forEach(item=>{
				this.rules[item] = this.rulesAll[item];
			})
		},
		submit(){
			this.$refs.uForm.validate().then(res => {
				this.saveBtn();
			}).catch(errors => {
				this.$util.showToast({title:'请完善信息'})
			})
		},
		saveBtn(){
			let data = {
				regno: this.regnoInfo.regno,
				ancheyear: this.year,
			}
			data = this.$util.setSaveFormData(this.formKeys,data,this.formData);
			this.$http.sendRequest({
				url: '/annual/report/ws-baseinfo/update-wsdebtinfo',
				method: 'PUT',
				data: data
			})
			.then(res=>{
				this.setRecord();
			})
			.catch(err=>{})
		},
		
		
		
		
		
		//存一下记录
		setRecord(){
			let fillingItem = this.$minFormType.get(this.minFormName);
			this.$http.sendRequest({
				url: '/annual/report/record',
				method: 'POST',
				data: {
					regno: this.regnoInfo.regno,
					year: this.year,
					fillingItem: fillingItem,
					isImp: '0',
				},
				hideLoad: true,
			})
			.then(res=>{
				uni.navigateBack();
			})
			.catch(err=>{})
		},
		goPage(path){
			uni.navigateTo({
				url: path
			})
		},
	}
}
</script>

<style lang="less" scoped>
.wrap{
	width: 100vw;
	min-height: 100vh;
	padding-top: 16rpx;
	box-sizing: border-box;
	position: relative;
	background-color: #FFF;
	
	.topBc{
		height: 10rpx;
		background-color: #F5F6F8;
	}
}

.content{
	padding: 30rpx 36rpx;
	background-color: #FFF;
	
	.title{
		color: #E4B269;
		font-size: 36rpx;
		font-weight: bold;
		border-left: 8rpx solid #E4B269;
		line-height: 40rpx;
		padding-left: 16rpx;
		margin-bottom: 30rpx;
		margin-top: 30rpx;
	}
	
	
}
</style>